using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InvestmentIntelligence.DbModel.Models.Mapping
{
    public class InvestmentMap : EntityTypeConfiguration<Investment>
    {
        public InvestmentMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Identity)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            // Table & Column Mappings
            this.ToTable("Investment", "Analytics");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.StartDate).HasColumnName("StartDate");
            this.Property(t => t.EndDate).HasColumnName("EndDate");
            this.Property(t => t.LastSerieDate).HasColumnName("LastSerieDate");
            this.Property(t => t.Side).HasColumnName("Side");
            this.Property(t => t.Closed).HasColumnName("Closed");
            this.Property(t => t.FundBookEntityId).HasColumnName("FundBookEntityId");
            this.Property(t => t.IdeaId).HasColumnName("IdeaId");
            this.Property(t => t.Identity).HasColumnName("Identity");
            
            this.HasRequired(t => t.Idea)
                .WithMany(t => t.Investments)
                .HasForeignKey(d => d.IdeaId);

            this.HasMany(t => t.TradedQuantities)
                .WithRequired(t => t.Investment)
                .HasForeignKey(t => t.InvestmentId);
        }
    }
}
